//
//  FSLPageView.swift
//  FSL-ScrollViewPage
//
//  Created by 我演示 on 2019/10/30.
//  Copyright © 2019 Jerry-Fu. All rights reserved.
//

import UIKit

class FSLPageView: UIView {

    fileprivate var titles: [String]
    fileprivate var childVcs : [UIViewController]
    fileprivate var parentVc : UIViewController
    fileprivate var style : FSLTitleStyle
    fileprivate var titleView : FSLPageTitleView?
    
    init(frame: CGRect , titles : [String] , childVcs : [UIViewController] , parentVc: UIViewController , titleStype : FSLTitleStyle ) {
        self.titles = titles
        self.childVcs = childVcs
        self.parentVc = parentVc
        self.style = titleStype
        super.init(frame: frame)
        
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

//MARK: -setUI界面
extension FSLPageView {
    
    fileprivate func setUpUI() {
        setUpTtitleView()
        setUpContentView()
    }
    private func setUpTtitleView() {
         let titleFrame = CGRect(x: 0, y: 0, width: bounds.width, height: style.titleHeight)
        titleView  = FSLPageTitleView(frame: titleFrame, titles: titles)
        
        addSubview(titleView!)
    }
    
    private func setUpContentView() {
     
        guard let showView = titleView else {
            return
        }
        
        let contentFrame = CGRect(x: 0, y: showView.frame.maxY , width: bounds.width, height: bounds.height - showView.frame.maxY)
       let contentView = FSLContentView(frame:contentFrame, childVcs: childVcs, pareneVc: parentVc)
        addSubview(contentView)
        
    }
    
}
